package com.unohacha.qqj.fzdr.personal.view.activity;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.unohacha.qqj.fzdr.R;
import com.unohacha.qqj.fzdr.personal.presenter.AuthenticationPresenter;
import com.unohacha.qqj.fzdr.personal.presenter.IAuthenticationPresenter;
import com.unohacha.qqj.fzdr.personal.view.IAuthenticationView;
import com.unohacha.qqj.fzdr.view.PublicStaticData;
import com.unohacha.qqj.mylibrary.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 认证中心
 */
public class AuthenticationCenterActivity extends BaseActivity implements IAuthenticationView {

    private IAuthenticationPresenter iAuthenticationPresenter;

    @BindView(R.id.common_back)
    ImageView commonBack;
    @BindView(R.id.common_title)
    TextView commonTitle;
    @BindView(R.id.common_right_image)
    ImageView commonRightImage;
    @BindView(R.id.common_right_text)
    TextView commonRightText;
 @BindView(R.id.tv_status)
    TextView tvStatus;
@BindView(R.id.tv_tip)
    TextView tvTip;

    // 显示认证状态
    @BindView(R.id.iv_authentication_state)
    ImageView ivAuthenticationState;
    @BindView(R.id.btn_personal_authentication)
    Button btn_personal_authentication;
    @BindView(R.id.btn_enterprise_authentication)
    Button btn_enterprise_authentication;

    // 个人认证 界面跳转 具体逻辑不在此页面
    @OnClick(R.id.btn_personal_authentication)
    void onPersonalAuthenticationClick() {
        jumpToOtherActivity(this, AuthenticationPersonalActivity.class);
    }

    // 企业认证 界面跳转 具体逻辑不在此页面
    @OnClick(R.id.btn_enterprise_authentication)
    void onEnterpriseAuthenticationClick() {
        jumpToOtherActivity(this, AuthenticationEnterpriseActivity.class);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_authentication_center;
    }

    @OnClick(R.id.common_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected void initView() {
//        super.initView();
        commonTitle.setText("认证中心");
        commonRightImage.setVisibility(View.INVISIBLE);

        // 初始化认证Presenter
        iAuthenticationPresenter = new AuthenticationPresenter(this);
        // 获取认证信息
        iAuthenticationPresenter.getAuthenticationState();
//        showLoading();
    }

    @Override
    protected void onResume() {
        super.onResume();
        // 更新认证信息
        iAuthenticationPresenter.getAuthenticationState();
    }

    @Override
    public void showAuthenticationState(String personal, String enterprise) {
        // 显示认证状态

        if (personal.equals("") && enterprise.equals("") || personal.equals("0") && enterprise.equals("0")) {
         //   Toast.makeText(getApplicationContext(), "未进行任何认证", Toast.LENGTH_SHORT).show();
        } else {
        //    Toast.makeText(getApplicationContext(), personal + enterprise, Toast.LENGTH_SHORT).show();
            switch (personal + enterprise) {
                case "00":
                    btn_personal_authentication.setVisibility(View.VISIBLE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    tvTip.setVisibility(View.VISIBLE);
                    tvStatus.setText("您尚未进行任何认证");
                    ivAuthenticationState.setImageResource(R.drawable.uncertified);
                    break;
                case "01":
                    btn_personal_authentication.setVisibility(View.VISIBLE);
                    btn_enterprise_authentication.setVisibility(View.GONE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_qiye);
                    tvTip.setVisibility(View.GONE);
                    tvStatus.setText("您已通过企业认证");
//                    PublicStaticData.sharedPreferences.edit().putBoolean("certification",true).commit();
                    break;
                case "02":
                    btn_personal_authentication.setVisibility(View.VISIBLE);
                    btn_enterprise_authentication.setVisibility(View.GONE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_applying);
                    tvTip.setVisibility(View.GONE);
                    tvStatus.setText("企业认证正在审核中");
                    break;
                case "03":
                    btn_personal_authentication.setVisibility(View.VISIBLE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_renzheng_fail);
                    tvTip.setVisibility(View.GONE);
                    tvStatus.setText("企业认证审核失败");
                    break;
                case "10":
                    btn_personal_authentication.setVisibility(View.GONE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_persion);
                    tvTip.setVisibility(View.GONE);
                    tvStatus.setText("您已通过个人认证");
                    break;
                case "11":
                    btn_personal_authentication.setVisibility(View.GONE);
                    btn_enterprise_authentication.setVisibility(View.GONE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_qiye);
                    tvTip.setVisibility(View.GONE);
                    tvStatus.setText("您已通过企业认证");
                    break;
                case "12":
                    btn_personal_authentication.setVisibility(View.GONE);
                    btn_enterprise_authentication.setVisibility(View.GONE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_applying);
                    tvTip.setVisibility(View.GONE);
                    tvStatus.setText("企业认证正在审核");
                    break;
                case "13":
                    btn_personal_authentication.setVisibility(View.GONE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_renzheng_fail);
                    tvStatus.setText("企业认证失败");
                    break;
                case "20":
                    btn_personal_authentication.setVisibility(View.GONE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_applying);
                    tvTip.setVisibility(View.GONE);
                    tvStatus.setText("个人认证正在审核");
                    break;
                case "21":
                    btn_personal_authentication.setVisibility(View.GONE);
                    btn_enterprise_authentication.setVisibility(View.GONE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_applying);
                    tvTip.setVisibility(View.GONE);
                    tvStatus.setText("个人认证正在审核");
                    break;
                case "22":
                    btn_personal_authentication.setVisibility(View.GONE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_applying);
                    tvStatus.setText("个人认证正在审核");
                    break;
                case "23":
                    btn_personal_authentication.setVisibility(View.GONE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_applying);
                    tvStatus.setText("个人认证正在审核");
                    break;
                case "30":
                    btn_personal_authentication.setVisibility(View.VISIBLE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_renzheng_fail);
                    tvStatus.setText("个人认证失败");
                case "31":
                    btn_personal_authentication.setVisibility(View.VISIBLE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_renzheng_fail);
                    tvStatus.setText("个人认证失败");
                    break;
                case "32":
                    btn_personal_authentication.setVisibility(View.VISIBLE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_renzheng_fail);
                    tvStatus.setText("个人认证失败");
                    break;
                case "33":
                    btn_personal_authentication.setVisibility(View.VISIBLE);
                    btn_enterprise_authentication.setVisibility(View.VISIBLE);
                    ivAuthenticationState.setImageResource(R.drawable.ic_renzheng_fail);
                    tvStatus.setText("个人认证失败");
                    break;

            }
        }
//        hideLoading();
    }
}
